﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web;
using ArkEC.CoreCom.Datastruct;

namespace ArkEC.CoreCom.Runtime
{
    /// <summary>
    /// 运行时设置参数
    /// </summary>
    public class RunSetting
    {
        /// <summary>
        /// 数据库连接字符
        /// </summary>
        public static readonly string ConnStr = ConfigurationManager.ConnectionStrings["ArkEC_Conn"].ConnectionString;
        
        /// <summary>
        /// 数据库类型
        /// </summary>
        public static readonly string ConnType = ConfigurationManager.AppSettings["ConnType"];

        /// <summary>
        /// 临时文件存放路径
        /// </summary>
        public static readonly string TempFilePath = ConfigurationManager.AppSettings["TempFilePath"];

        /// <summary>
        /// 执行动作映射文件路径
        /// </summary>
        public static readonly string ActionMappingFilePath = ConfigurationManager.AppSettings["ActionMappingFilePath"];

        private static Dictionary<string, string> GetRunningSettting()
        {
            Dictionary<string, string> setting = new Dictionary<string, string>();

            string runSettingStr = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["RunSetting"].Value);
            ItemStruct runningParams = ObjectConvertion.JsonToObject<ItemStruct>(runSettingStr);

            foreach (Dictionary<string, string> item in runningParams.items)
            {
                setting.Add(item["key"], item["value"]);
            }

            return setting;
        }

        /// <summary>
        /// 获取当前运行的语言
        /// </summary>
        /// <returns></returns>
        public static string GetRunningLanguage()
        {
            Dictionary<string, string> setting = GetRunningSettting();

            return setting["language"];
        }

        public class ItemStruct
        {
            public List<Dictionary<string, string>> items = new List<Dictionary<string, string>>();
        }
    }
}
